<?php

$action = getAction();

switch ($action) {
	case "index":
		$month = date("Y-m");
		$month1 = date('Y-m',strtotime("-1 month"));
		$month2 = date('Y-m',strtotime("-2 month"));
		
		$order = $db->getAll("select * from " . table("order") . " where  openid = '$openid' and insert_time like '$month%' order by id desc");
		
		for($i = 0; $i < count($order); $i++) {
			$order[$i]["status_name"] = ORDER_STATUS::getOrderStatusName($order[$i]["status"]);
			$order[$i]["range_name"] = USE_RANGE::getRangeName($order[$i]["use_range"]);
			$order[$i]["mobile_type_name"] = MOBILE_TYPE::getTypeName($order[$i]["mobile_type"]);
		}
		
		$monthArray[$month2] = substr($month2, 0, 4) . '年<em class="month">' . substr($month2, 5) . "</em>月";
		$monthArray[$month1] = substr($month1, 0, 4) . '年<em class="month">' . substr($month1, 5) . "</em>月";
		$monthArray[$month] = substr($month, 0, 4) . '年<em class="month">' . substr($month, 5) . "</em>月";
		
		$smarty->assign("order", $order);
		$smarty->assign("monthArray", $monthArray);
		$smarty->assign("monthStr", substr($month, 0, 4) . '年<em class="month">' . substr($month, 5) . "</em>月");
		$smarty->display("order.html");
		break;
	case "get":
		
		$month = trim($_POST["month"]);
		
		$order = $db->getAll("select * from " . table("order") . " where  openid = '$openid' and insert_time like '$month%' order by id desc");
		
		for($i = 0; $i < count($order); $i++) {
			$order[$i]["status_name"] = ORDER_STATUS::getOrderStatusName($order[$i]["status"]);
			$order[$i]["range_name"] = USE_RANGE::getRangeName($order[$i]["use_range"]);
			$order[$i]["mobile_type_name"] = MOBILE_TYPE::getTypeName($order[$i]["mobile_type"]);
		}
		
		$result["orders"] = $order;
		
		echo json_encode($result);
		exit();
		break;
}
?>